package com.yc.jpyy.mobile.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

import com.etrans.ecpm.impl.RdtIntfWebImpl;
import com.etrans.ecpm.intf.CallBack;
import com.etrans.ecpm.intf.TCmdReply;
import com.etrans.ecpm.intf.TCmdSendResp;
import com.etrans.ecpm.intf.TCmdStepInfo;
import com.etrans.ecpm.intf.UReqObj;
import com.etrans.lib.ShortUUID;


public class Test {
	private final static Logger logger = LoggerFactory.getLogger(Test.class);
	
	 public static void main(String[] _args) throws Exception {
		      RdtIntfWebImpl impl = new RdtIntfWebImpl();
			  String rds_fix = "27.188.64.102:16379:foobared";
			  String rds_dyn = "27.188.64.102:16389:foobared";
			  impl.setup(rds_dyn, rds_fix, rds_dyn, rds_fix);
			  String args = "2,0,0,1,0,测试发指令" ;
			  UReqObj req = new UReqObj(UUID.randomUUID(), System.currentTimeMillis(), 197, 2,69929, 950, "100900010001", 0x8300, args) ;
			  String req_key = ShortUUID.uuidToStr(req.getUuid());
			  impl.sendCMDAsyn(req, new CallBack() {
					public void onCompletion(TCmdSendResp resp) {
						if(null == resp) {
				        	logger.info("没有获取到回复对象");
				        	return ;
				        }
						try {
							TCmdStepInfo stepInfo = impl.getCmdStepInfo(req.getUuid(), 30);
							TCmdReply reply = null;
							if (stepInfo.hasReply()) {
							    reply = impl.getReply(req.getMType(), req.getMCode(), req.getCmd(), resp.getCmdPkgSeq(), 30);
							    if (null != reply) {
							    	logger.info("收到指令回复：{}-{}",req.getMCode(),req_key);
							    }else {
							    	logger.info("等待终端应答超时：{}",req.getMCode());
							    }
							}else {
								logger.info("终端没有回复：{}",req.getMCode());
							}
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				});
	 }
	
}
